package group9;

import java.io.IOException;

import javax.jdo.PersistenceManager;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author Claudio Herreros, Dylan James, Tyler Berg
 *
 */
public class RemoveUserStoryServlet extends HttpServlet {
	/* (non-Javadoc)
	 * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 * 
	 */
	public void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {

		UserStory currentUserStory = (UserStory) (req.getSession()
				.getAttribute("UserStory")); 

		PersistenceManager pm = PMF.get().getPersistenceManager();
		try {
			pm.currentTransaction().begin();
			currentUserStory = (UserStory) pm.getObjectById(currentUserStory
					.getClass(), currentUserStory.getKey());
			pm.deletePersistent(currentUserStory);
			pm.currentTransaction().commit();
			resp.sendRedirect("/MyUserStories.jsp");
		} finally {
			if (pm != null && !pm.isClosed())
				pm.close();
		}
	}
}
